package com.mhh.selary.backend.dao.mapper.project;

import com.mhh.motor.mybatis.base.BaseMapper;
import com.mhh.selary.backend.dao.entity.project.SelaryProjectEntity;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * SelaryProjectMapper
 *
 * @author 人工智能
 * @date 2020-09-14 15:43:09
 */
public interface SelaryProjectMapper extends BaseMapper<SelaryProjectEntity> {

    /**
     * 查询用户有权限的项目列表
     *
     * @param userId
     * @return
     */
    @Select("select * from selary.selary_project\n" +
            "where\n" +
            "(project_scope = 1 and is_delete = 0 and exists (select 1 from selary.selary_user_project where user_id = #{userId} and is_delete = 0 and selary_project.id = selary_user_project.project_id))\n" +
            "or\n" +
            "(project_scope = 2 and is_delete = 0 and create_by = #{userId})")
    List<SelaryProjectEntity> queryByUser(Long userId);

}
